<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8" isELIgnored="false"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>运营人员管理</title>
<script type="text/javascript">
$(function()
	    {	$.jgrid.ajaxOptions.type = 'post';
	        $("#gridTable").jqGrid({
	        		url:'user/view',
	        		datatype: "json",
	        		autowidth:true, 
	        		rownumbers:true,
	                height: 270,
	                colNames:['id','用户名','真实姓名', '联系电话', '邮箱','用户状态', '操作'],
	                colModel:[
							{name:'id',index:'id',hidden:true},
	                        {name:'userName',index:'userName', width:100},
	                        {name:'realName',index:'realName', width:90},
	                        {name:'telephone',index:'telephone', width:90},
	                        {name:'email',index:'email', width:90},  
	                        {name:'status',index:'status', width:90},
	                       // {name:'orgName',index:'orgName', width:125},
	                        {name:'oper',index:'oper', width:90}
	                ],
	                viewrecords:true,
	                rowNum:10,
	                rowList:[10,20],
	                postData:{source:'PAY'},
	                gridComplete: function(){
	                	var ids = jQuery("#gridTable").jqGrid('getDataIDs');
	                	for(var i=0;i<ids.length;i++){
	                		var rowdata = jQuery("#gridTable").getRowData(ids[i]);
	                		if(rowdata['status'] == 'normal'){
	                			$("#gridTable").jqGrid("setRowData",ids[i],{status:'正常'});
	                		}else if(rowdata['status'] == 'lock'){
	                			$("#gridTable").jqGrid("setRowData",ids[i],{status:'禁用'});
	                		}else if(rowdata['status'] == 'LOSS'){
	                			$("#gridTable").jqGrid("setRowData",ids[i],{status:'挂失'});
	                		}else{
	                			$("#gridTable").jqGrid("setRowData",ids[i],{status:'注销'});
	                		}
	        				var id=rowdata['id'];
	        				var username=rowdata['userName'];
	        				if(rowdata['status'] == 'normal'){
	                			jQuery("#gridTable").jqGrid('setRowData',ids[i],{oper:'<shiro:hasPermission name="user:modify"><a class="btn" href="#" onclick="modifyDialog('+id+')">修改</a> </shiro:hasPermission> '
	                															+'<shiro:hasPermission name="user:delete"> <a class="btn" href="#" onclick="delDialog('+id+')">删除</a> </shiro:hasPermission>'});
	        				}else if(rowdata['status'] == 'lock'){
	                			jQuery("#gridTable").jqGrid('setRowData',ids[i],{oper:'<shiro:hasPermission name="user:modify"><a class="btn" href="#" onclick="modifyDialog('+id+')">修改</a> </shiro:hasPermission> '
	                															+'<shiro:hasPermission name="user:delete"> <a class="btn" href="#" onclick="delDialog('+id+')">删除</a> </shiro:hasPermission>'});
	        				}
	        			}
	                },
	                jsonReader: {  
	                	root:"data",
	                    page:"index",
	                    total:"total",
	                    records:"totalRecord",    
	                    repeatitems : false  
	                },
	                pager:"#pgtoolbar1"
	        });
	        });
	
var myDialog;
	function delDialog(id){
		myDialog = art.dialog({
			lock:true,
		    content: '是否确定删除此用户?',
		    ok: function () {
		    	jQuery.ajax({
					url: "user/del/"+id+"?rand="+Math.random(),
					tokenId: 'user_delete',		
					success: function (data) {
						 myDialog =  art.dialog({icon: data.success,content: data.message,lock:true});
				        	$("#gridTable").trigger("reloadGrid", [{page:1}]);
					}
				});
		    },
		    cancelVal: '关闭',
		    cancel: true //为true等价于function(){}
		});
		
	}
	
	function modifyDialog(id){
		showDialog('user/modify/page?id='+id+'&rand='+Math.random(),{width:'900px',title:'运营用户修改',lock:true});
	}
	
	function unboundCard(userName){
		myDialog = art.dialog({
			lock:true,
		    content: '解绑后该用户将无法登陆系统，确认解绑权限卡?',
		    ok: function () {
		    	jQuery.ajax({
					url: "user/unboundCard/"+userName+"?rand="+Math.random(),
					type:'POST',
					data:'userName='+userName,
					success: function (data) {
						 myDialog =  art.dialog({icon: data.success,content: data.message,lock:true});
				        	$("#gridTable").trigger("reloadGrid", [{page:1}]);
					}
				});
		    },
		    cancelVal: '关闭',
		    cancel: true //为true等价于function(){}
		}); 
	}
	
	function showDialog(url,options){
		myDialog = art.dialog(options);// 初始化一个带有loading图标的空对话框
		jQuery.ajax({
			url: url,
			success: function (data) {
			myDialog.content(data);// 填充对话框内容
			}
		});
	}
	function search(){
		var param = {userName:$('#userName').attr("value"),realName:$('#realName').attr("value"),status:$('#status').attr("value"),orgName:$('#orgName').attr("value")};
		var postData = $("#gridTable").jqGrid("getGridParam", "postData");  
		$.extend(postData,param);
		$("#gridTable").jqGrid("setGridParam").trigger("reloadGrid", [{page:1}]);   
	}
		
	
</script>
</head>
<body>
	<div class="modal">
	<div class="modal-header r_location">
			<i class="r_txtico"></i>查询运营人员
		</div>
		<div style="margin-left: 10px;">
			<div>
				<form id="uForm" action="">
					<ul class="all_list">
						  <li><span class="all_title">用户名：</span><span>
							<input type="text" id="userName" name="userName" value="${userName}" class="ui_input" />
							</span>
						   <span class="all_title">真实姓名：</span><span>
							<input type="text" id="realName" name="realName" value="${realName}" class="ui_input" />
							</span> 
						   <span class="all_title">用户状态：</span><span>
								  <select id="status" name="status" class="ui_input" >
							  	<option value="">请选择</option>
							  	<option value="normal">正常</option>
							  	<option value="lock">禁用</option>
							  	<option value="CANCEL">注销</option>
							  </select>
							</span>
							</li>
						  <li class="m-t10"><span class="all_title"></span><span>
							<input type="button" class="search_btn m-r15" value="查 询" name="button" onclick="search()" />
							<input type="reset" class="reset_btn" value="重 置" name="button">
							</span></li>
					</ul>
					<table  id="gridTable">
					</table>
					<div id="pgtoolbar1"></div>
				</form>
			</div>
		</div>
	</div>
</body>
</html>